package future;

import com.google.common.util.concurrent.*;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.List;

public class Test04 {
    public static void main(String[] args) {
        ListeningExecutorService service = MoreExecutors.newDirectExecutorService();
        ListenableFuture<Integer> future1 = service.submit(() -> 1);
        ListenableFuture<Integer> future2 = service.submit(() -> 2/0);
        ListenableFuture<List<Object>> futureList = Futures.successfulAsList(future1, future2);
        Futures.addCallback(futureList, new FutureCallback<>() {
            @Override
            public void onSuccess(@Nullable List<Object> objects) {
                System.out.println(objects);
            }

            @Override
            public void onFailure(Throwable throwable) {
                throwable.printStackTrace();
            }
        }, service);
    }
}
